package ru.maxmatveev.dyndao.demo.dao;

import ru.maxmatveev.dyndao.*;
import ru.maxmatveev.dyndao.demo.model.SomeEntity;

import java.util.List;

/**
 * @author Max Matveev
 *         Date: Jan 4, 2009
 *         Time: 3:58:26 PM
 */
public abstract class SimpleEntityDao implements DynamicDao<SomeEntity, Long> {

    @Ordering.Field(fieldName = "value1")
    public abstract List<SomeEntity> getOrderedByField();

    public abstract List<SomeEntity> getOrderedByCriteria(
            @Ordering.Criteria Ordering criteria
    );

    public abstract List<SomeEntity> getPaginated(
            @Pagination.Paginate Pagination pagination
    );

    @Count
    public abstract Integer getCount();

    public abstract List<SomeEntity> getFilteredByField(
            @Restriction.Field(comparison = Restriction.Comparison.ILIKE, fieldName = "value2") String value
    );

    public abstract List<SomeEntity> getFilteredByCriteria(
            @Restriction.Restrict Restriction restriction
    );

    public abstract List<SomeEntity> getPaginatedFilteredByCriteriaOrderedByCriteria(
            @Pagination.Paginate Pagination pagination,
            @Restriction.Restrict Restriction restriction,
            @Ordering.Criteria Ordering ordering
    );

    @Count
    public abstract Integer getCountFilteredByCriteria(
            @Restriction.Restrict Restriction restriction
    );

    public Integer getCountPredefined() {
        return getCountFilteredByCriteria(Restriction.or(Restriction.ieq("value1", "vaLue 1 1"), Restriction.eq("value2", "value 2 2")));
    }

    @Hql(query = "FROM SomeEntity WHERE id IN (:ids)")
    public abstract List<SomeEntity> findByIds(@Named("ids") List<Long> ids);

    @Hql(query = "UPDATE SomeEntity SET value1=? WHERE id=?")
    public abstract void updateById(String newValue, Long id);

    @Hql(query = "FROM SomeEntity WHERE id=?")
    public abstract SomeEntity getWithHqlById(Long id);

    @Hql(query = "FROM SomeEntity")
    public abstract List<SomeEntity> getAllWithHql();

}
